Skip to content

feat(opencode): add OpenCode Go quota tracking provider - #109

Merged
prakersh merged 4 commits into
onllm-dev:mainfrom
hiyukoim:feat/opencode-provider-v2
Jul 27, 2026
Merged

feat(opencode): add OpenCode Go quota tracking provider#109
prakersh merged 4 commits into
onllm-dev:mainfrom
hiyukoim:feat/opencode-provider-v2

Conversation

@hiyukoim

Copy link
Copy Markdown
Contributor

Summary

Replaces closed #102 since it got messy. Rebuilds OpenCode Go as a quota provider on current upstream/main (keeps Kimi / Moonshot / DeepSeek), following the existing provider pattern from CONTRIBUTING.md. Related: #100.

  • Agent + tracker + SQLite store for OpenCode Go snapshots (5-hour / weekly / monthly)
  • Dashboard tab, charts, deep insights, menubar card, settings UI
  • Config via OPENCODE_GO_WORKSPACE_ID + OPENCODE_GO_AUTH_COOKIE (see docs/OPENCODE_SETUP.md)
  • OPENCODE_ENABLED remains the separate Codex-via-OpenCode-auth path
  • Frontend contract: quota JSON uses limit (not limitValue); empty-state re-render guarded; dedicated history routing

Why a new PR

#102 was closed after an unrelated-histories merge onto the harden branch corrupted history / app.js. This branch starts clean from upstream/main and ports OpenCode-only changes.

Provider checklist

Per CONTRIBUTING "Adding a New Provider":

  1. internal/api/opencode*.go
  2. internal/store/opencode_store.go (+ schema in store.go)
  3. internal/tracker/opencode_tracker.go
  4. internal/agent/opencode_agent.go
  5. Endpoints in internal/web/handlers.go / opencode_handlers.go
  6. Dashboard tab + charts in internal/web/static/app.js

Test plan

  • Focused short tests: api, web, agent, store, tracker, config
  • go vet ./...
  • CI green on this PR
  • With OPENCODE_GO_WORKSPACE_ID + OPENCODE_GO_AUTH_COOKIE set: OpenCode tab appears, quotas poll, charts update
  • Without OpenCode env: other providers unchanged, no OpenCode tab noise
./app.sh --smoke
# optional full suite:
./app.sh --test

hiyukoim and others added 3 commits July 24, 2026 12:29
Rebuild PR work cleanly from upstream (keeps kimi/moonshot/deepseek).
Hardened scrape client, tracker wiring, typed errors, dashboard/UI,
limit-field contract test, and empty-state/history frontend fixes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Prevent DetectCodexCredentials from reading the host OpenCode
auth.json when CODEX_HOME auth is empty.

Co-authored-by: Cursor <cursoragent@cursor.com>
Pin OPENCODE_HOME to a temp dir in tests so host auth.json
cannot leak on macOS. Add menubar/tab/historyBoth/settings
and document OPENCODE_GO_* in .env.example.
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

@prakersh

Copy link
Copy Markdown
Contributor

Thanks for the clean rebuild - this follows the provider pattern well and the limit-key regression test from #102 is appreciated. CI is green. A few things before merge:

  1. Auth vs parse errors: the client follows redirects, so an expired cookie likely hits a 302→login page→200 and surfaces as ErrOpenCodeParseFailed instead of ErrOpenCodeUnauthorized. Setting CheckRedirect to http.ErrUseLastResponse and mapping 3xx to unauthorized would fix this (also keeps the cookie out of redirect chains).
  2. False cycle resets in fallback mode: the data-slot parser has hour granularity, so recomputed ResetsAt can jump ~59 min between polls - past the 10-min threshold in the tracker, spuriously closing weekly/monthly cycles. Suggest a wider threshold (~90 min) or requiring a utilization drop.
  3. TestOpenCodeAgent_Poll_FetchErrorNoInsert hits the real opencode.ai - please use the stub client or an httptest server; tests here must be hermetic.
  4. Cookie heuristic: Contains(cookie, "=") misfires if the raw value contains = (base64 padding). Prefer an auth= prefix check.
  5. Late-appearing quotas never render: cards render once, then update by ID - if monthly shows up after the first render, it gets no card until reload. Re-render when the incoming quota set differs from the rendered cards.

Co-Authored-By: codex <codex@openai.com>
@hiyukoim
hiyukoim force-pushed the feat/opencode-provider-v2 branch from 9f57209 to ae5c59c Compare July 27, 2026 07:41
@hiyukoim

Copy link
Copy Markdown
Contributor Author

@prakersh Thanks for the detailed review!! I’ve fixed all five points in 9f57209:
Could you please take a look and let me know what you think? Thank you again :)


  • Disabled redirect following and map all 3xx dashboard responses to ErrOpenCodeUnauthorized.
  • Fixed raw padded cookie values so token== becomes auth=token==.
  • Made the agent fetch-error test hermetic with the existing stub client.
  • Re-rendered OpenCode quota cards whenever the quota-name set changes.
  • Added a 90-minute fallback reset-time tolerance, including the case where a coarse stored timestamp has passed but the incoming reset time is still future within tolerance.

Added regression coverage for each case. The targeted race-enabled tracker suite passes.

@prakersh prakersh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed - all five points are properly addressed, each with regression coverage. Nice work.

  • Redirects: ErrUseLastResponse + 3xx→unauthorized, and the test asserts the redirect target gets zero hits, so the cookie never travels down the chain.
  • Reset drift: the 90-minute tolerance plus the currentResetIsFuture guard absorbs hour-granularity noise, and genuine resets are still caught by the api-based branch since those jump 5h/7d.
  • Hermetic tests: the remaining real-client uses are missing-config paths that return before any HTTP call.
  • Cookie prefix and quota-set re-render both look right.

Verified locally on your branch merged with current main (v2.13.2): clean merge, go vet clean, go test -race ./... green across all packages. CI is green too.

Merging as a squash - main requires linear history. Thanks for the thorough follow-up, and for rebuilding this cleanly after #102.

@prakersh
prakersh merged commit 6989fa6 into onllm-dev:main Jul 27, 2026
3 checks passed
prakersh added a commit that referenced this pull request Jul 27, 2026
Adds the OpenCode Go provider merged in #109 (thanks @hiyukoim):
5-hour / weekly / monthly subscription quota tracking scraped from
the authenticated OpenCode Go dashboard, with cycle history, deep
insights, menubar card, and settings UI.

Docs:
- README: OpenCode Go provider bullet + OPENCODE_GO_* env var rows
- CLAUDE.md: refresh stale provider count (9 -> 15) and setup-doc list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants